<?php

session_start();
class cadastroTema extends Tpage{

	public function onLoad($param)
    {
        parent::onLoad($param);
        if(!$this->IsPostBack)
        {
        $_disciplina = disciplinaRecord::finder()->findAll();
			
			foreach ($_disciplina as $dados=>$valor){

				$vetor []= (array(
            					'PKCodStrDisciplina'=>$valor->PKCodStrDisciplina,
            					'disciplina'=>$valor->StrDisciplina,
				));
			}
            $data = $vetor;
           	
            $this->usuarioLogado->Text = $_SESSION['usuario'];
            
           	$this->Disciplina->DataSource=$data;
            $this->Disciplina->dataBind();
            
        }
    }
	
	
	public function saveRecord($sender, $param){
		$idDisciplina = $this->collectSelectionResult($this->Disciplina);
		
		
		$tema = new temaRecord();
		
		$tema->FKCodLongUsuario = $_SESSION['idUsuario'];
		$tema->StrTema = $this->tema->Text;
		$tema->FKCodStrDisciplina = $idDisciplina;
		
		$tema->save();
		
		$this->tema->Text = "";
		$this->mensagen->Text ="cadastro efetuado com sucesso";
		$this->panel1->render($param->NewWriter);
	
	}
	
 protected function collectSelectionResult($input)
    {
        $indices=$input->SelectedIndices;
        $result='';
        foreach($indices as $index)
        {
            $item=$input->Items[$index];
            $result = $item->Value;
        }
        return $result;
    }
}
?>